import matplotlib.pyplot as plt
import numpy as np
import os

def cr():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    cr_data = [0.7256172595600472, 0.8856581102475849, 0.8914171257073252, 0.8928399343812733, 0.8948211710978226, 0.8947920307384247, 0.896243946758593, 0.7345910871988877, 0.8962585169382917, 0.8854832928609523, 0.721761711885872, 0.721761711885872]
    plt.bar(x_data,cr_data,color="deepskyblue",label="Average Completion Rate")

    #line
    ave_us_data = [0.6503260000000002, 0.7878597999999998, 0.7948477999999995, 0.7953206000000002, 0.7955968, 0.7955781999999999, 0.8011252, 0.7068346, 0.8020130000000002, 0.7834008000000001, 0.6332998000000001, 0.6332998000000001]
    worst_us_data = [0.64629, 0.78388, 0.79133, 0.78971, 0.79206, 0.79206, 0.79687, 0.70173, 0.79878, 0.77966, 0.62991, 0.62991]
    ave_Comp_ratio = [0.7311798700276586, 0.8858130017314655, 0.8936698072901443, 0.8942013896696724, 0.8945119291223493, 0.8944910166175708, 0.9007276652200309, 0.7947140833352071, 0.9017258438083247, 0.8807996222257204, 0.7120368329922875, 0.7120368329922875]
    worst_Comp_ratio = [0.7266420813563895, 0.8813384003058172, 0.8897146454993141, 0.8878932337928088, 0.8905354050954555, 0.8905354050954555, 0.8959434238042769, 0.7889748375345731, 0.898090890692811, 0.8765937352431922, 0.7082255852128353, 0.7082255852128353]
    plt.plot(x_data, ave_us_data, color = "sandybrown", marker='>', ms=3, label="ave_us")
    plt.plot(x_data, worst_us_data, color = "crimson", marker='o', ms=3, linestyle='-.', label="worst_us")
    plt.plot(x_data, ave_Comp_ratio, color = "plum", marker='*', ms=3, label="ave_compratio")
    plt.plot(x_data, worst_Comp_ratio, color = "indigo", marker='o', ms=3,linestyle='--', label="worst_compratio")
    plt.legend()
    plt.title('Completion rate & US & CompRatio')
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    cr()
        
